package mongodb

import (
	"beergo/lib/tool"
	"fmt"
)

func CreateController(c *Creator) {
	//tplFromTemplate := ReadTpl("controller")
	//tplCur := strings.ReplaceAll(tplFromTemplate, "__MODEL_NAME__", c.Table.Name)
	//tplCur = strings.ReplaceAll(tplCur, "__APP_NAME__", appName)
	//dir := c.Table.Path
	//tplCur = strings.ReplaceAll(tplCur, "__DIR__", dir)

	content:=twigger.Render("/mongodb/controller.twig",c)
	createControllerFile(c, []byte(content))
}

func createControllerFile(c *Creator, content []byte) {
	path := fmt.Sprintf(
		"%s/app/%s/auto/controller/%sMongoDbController.go",
		root, c.Table.Path, c.Table.Name)
	tool.CreateFile(path, content)
}

func CreateEmptyController(c *Creator) {
	//tplFromTemplate := ReadTpl("controller_admin")
	//tplCur := strings.ReplaceAll(tplFromTemplate, "__MODEL_NAME__", c.Table.Name)
	//tplCur = strings.ReplaceAll(tplCur, "__APP_NAME__", appName)
	//dir := c.Table.Path
	//tplCur = strings.ReplaceAll(tplCur, "__DIR__", dir)
	//createEmptyControllerFile(c, []byte(tplCur))
	//return tplCur
	content:=twigger.Render("/mongodb/controller_admin.twig",c)
	createEmptyControllerFile(c, []byte(content))
}

func createEmptyControllerFile(c *Creator, content []byte) {
	path := fmt.Sprintf(
		"%s/app/%s/controller/admin/%sMongoDbAdminController.go",
		root, c.Table.Path, c.Table.Name)
	if !tool.FileExist(path) || true {
		tool.CreateFile(path, content)
	}
}
